import time
import numpy as np
from RA_Cal import ReflectArray_cal_FFT, Para_RA, MASK_rp, Costfunction, csvtest
import random

if __name__ == '__main__':
    import DPGA
    Costfunction_400 = Costfunction.Costfunction_tt(400)
    ga_test = DPGA.DPGA(fitness_func=Costfunction_400.CostFunction, n=Costfunction_400.n_code,
                        population_size=400, generations=5000, casei=5)
    optimized_code, optimized_result = ga_test.run()

    # Code_bestsofar = csvtest.Read_csv_inrows(r"best/DPGA_result.csv", [0])[:, 0]
    # Code_bestsofar = csvtest.Read_csv_inrows(r"GA_test_22.csv", range(cf.n_code))[-1]
    # allt = 0
    # for i in range(1000):
    #     popu_rand = [random.randint(0, 1) for _ in range(952*4)]
    #     st = time.time()
    #     cf.CostFunction(0, popu_rand)
    #     allt += time.time()-st
    # print("time: ", allt)

    # print("")
    # print(cf.CostFunction_View(0, popu_rand))
    # print("")

    # Code_bestsofar = csvtest.Read_csv_inrows(r"best\best_2.csv", [0])[:, 0]
    # # Code_bestsofar = csvtest.Read_csv_inrows(r"GA_test_22.csv", range(cf.n_code))[-1]
    # print(cf2.n_code)
    # print(cf2.CostFunction_View(Code_bestsofar))
    # print("")
    #
    # popu_rand = [random.randint(0, 1) for _ in range(len(Code_bestsofar))]
    # print(Costfunction.CostFunction_View(popu_rand))